<?php 

session_start();
include_once("../includes/config.php");
include_once("../includes/mod_function.inc.php");

global $TOP_CONTENT_CATEGORY_SID,$TOP_AREA_CATEGORY_SID,$VERIFY_MOTHER_IMAGE_PATH,$VERIFY_MOTHER_IMAGE_NAME ;
global $foxydb;

$DOCUMENT_ROOT = $_SERVER["DOCUMENT_ROOT"];
$_DEBUG = false;


$ptype='relatedlink';
$paction = $_REQUEST['action'];
$purl = $_REQUEST['url'];

$pattern = "/[\?&](.*)/i";
$replacement = "";
$purl = preg_replace($pattern, $replacement, $purl);

$ptitle = urldecode($_REQUEST['title']);

$foxydb->open();

$linkLog = $foxydb->findLinkLog($purl,$usersid);

$usersid = ip_address_to_number($_SERVER['REMOTE_ADDR']);
if( $paction == 'savelink'){
	if($_REQUEST['tag']) $tags = implode(",",$_REQUEST['tag']);
	
	if($tags && $_REQUEST['tags']) $tags = $tags.",".$_REQUEST['tags'];
	else if($_REQUEST['tags']) $tags = $_REQUEST['tags'];

	$foxydb->saveLinkLog($purl, $_REQUEST['name'], $tags, $_REQUEST['desc'], $_REQUEST['linktype'], $usersid);
}

$hottags = $foxydb->selectHotTagsByUrl($purl,10);

$linkLogs = $foxydb->selectLinkLogByUserSid($usersid,100,0);
$foxydb->close();

include_once("../includes/header.php");
 
?>

  <hr>
  <table align=center width="100%" cellpadding=0 cellspacing=0>
    <tr>
      <td>
          <TABLE align=left width="100%" cellpadding=0 cellspacing=0>
            <TR>
              <TD nowrap='true' colspan="4" align="center" ><b>推荐文章</b></TD>
            </TR>
            <TR><TD colspan="4"><hr></TD></TR>
			<?php 
			if( $paction == 'savelink'){
			?>
				<TR><TD colspan="4" >谢谢你推荐文章：<br>
				<?php 
						echo "<A href='".$_REQUEST['url']."' target='_blank'>".$_REQUEST['name']."</A>";
				?>
				</TD></TR>
			<?php
			}else{
			?>
				<form action='savelink.php' method='POST' cellpadding=0 cellspacing=0>
				  <input type='hidden' name='action' value='savelink'/>

					<TR><TD>&nbsp;</TD></TR>
					<TR>
					  <TD></TD>
					  <TD nowrap='true' align='right' valign='top'>文章地址：</TD>
					  <TD>
							<INPUT TYPE="text" NAME="url" readonly value='<?php echo $purl;?>' size="60">(参数收藏时将被删除)
					  </TD>
					</TR>

					<TR>
					  <TD></TD>
					  <TD nowrap='true' align='right' valign='top'>文章标题：</TD>
					  <TD>
							<INPUT TYPE="text" NAME="name" value='<?php if($linkLog['linkname'] && $linkLog['linkname']!="") echo $linkLog['linkname']; else echo $ptitle;?>' size="60">
					  </TD>
					</TR>

					<TR>
					  <TD></TD>
					  <TD nowrap='true' align='right' valign='top'>文章类别：</TD>
					  <TD>
							<INPUT TYPE="radio" NAME="linktype" value='1' checked>休闲
							<INPUT TYPE="radio" NAME="linktype" value='2' <?php if($linkLog['linktype'] === '2') echo "checked"?>>体育
							<INPUT TYPE="radio" NAME="linktype" value='3' <?php if($linkLog['linktype'] === '3') echo "checked"?>>健康
							<INPUT TYPE="radio" NAME="linktype" value='4' <?php if($linkLog['linktype'] === '4') echo "checked"?>>参考
							<INPUT TYPE="radio" NAME="linktype" value='5' <?php if($linkLog['linktype'] === '5') echo "checked"?>>商业
							<INPUT TYPE="radio" NAME="linktype" value='6' <?php if($linkLog['linktype'] === '6') echo "checked"?>>家庭
							<INPUT TYPE="radio" NAME="linktype" value='7' <?php if($linkLog['linktype'] === '7') echo "checked"?>>新闻
							<INPUT TYPE="radio" NAME="linktype" value='8' <?php if($linkLog['linktype'] === '8') echo "checked"?>>儿童及青少年<br/>
							<INPUT TYPE="radio" NAME="linktype" value='9' <?php if($linkLog['linktype'] === '9') echo "checked"?>>游戏
							<INPUT TYPE="radio" NAME="linktype" value='10' <?php if($linkLog['linktype'] === '10') echo "checked"?>>社会
							<INPUT TYPE="radio" NAME="linktype" value='11' <?php if($linkLog['linktype'] === '11') echo "checked"?>>科学
							<INPUT TYPE="radio" NAME="linktype" value='12' <?php if($linkLog['linktype'] === '12') echo "checked"?>>艺术
							<INPUT TYPE="radio" NAME="linktype" value='13' <?php if($linkLog['linktype'] === '13') echo "checked"?>>购物
							<INPUT TYPE="radio" NAME="linktype" value='14' <?php if($linkLog['linktype'] === '14') echo "checked"?>>人物
							<INPUT TYPE="radio" NAME="linktype" value='15' <?php if($linkLog['linktype'] === '15') echo "checked"?>>商品
							<INPUT TYPE="radio" NAME="linktype" value='16' <?php if($linkLog['linktype'] === '16') echo "checked"?>>计算机
					  </TD>
					</TR>

					<TR>
					  <TD></TD>
					  <TD nowrap='true' align='right' valign='top'>文章标签：</TD>
					  <TD>
							<INPUT TYPE="text" NAME="tags" value='<?php echo $linkLog['tag']; ?>' size="60">(使用,分隔)
					  </TD>
					</TR>

					<?php if ($hottags){?>
					<TR>
					  <TD></TD>
					  <TD nowrap='true' align='right' valign='top'>热门标签：</TD>
					  <TD>
							<?php foreach($hottags as $tag){?><INPUT TYPE="checkbox" NAME="tag[]" value="<?php echo $tag['name'];?>" ><?php echo $tag['name'];?><?php }?>
					  </TD>
					</TR>
					<?php }?>

					<TR>
					  <TD></TD>
					  <TD nowrap='true' align='right' valign='top'>摘要：</TD>
					  <TD>
							<TEXTAREA name='desc' cols='56' rows='4'><?php echo $linkLog['description']; ?></TEXTAREA>
					  </TD>
					</TR>


					<TR><TD>&nbsp;</TD></TR>
					<TR><TD colspan="2">&nbsp;</TD><TD><font color='red'>
					请推荐技术研究，产品评价，商家介绍等有参考价值的文章网址；
					<br>禁止收集论坛的讨论贴、回帖、娱乐八卦等时效性大的文章网址；
					<br>禁止收集搜索引擎搜索生成的网址；
					</font></TD></TR>

					<TR>
					  <TD colspan="2"></TD>
					  <TD><INPUT TYPE="submit" name='submit' value='保存'></TD>
					  <TD></TD>
					</TR>

					</form>
			<?php }?>

			<?php if ($linkLogs){?>
				<TR>
				  <TD nowrap='true' colspan="4" align="center" ><b>你推荐的文章</b></TD>
				</TR>
				<TR>
				  <TD nowrap='true'  colspan="4">
					<?php foreach($linkLogs as $ll){?>
						<A href='<?php echo $ll['linkurl']?>' target='_blank'><?php echo $ll['linkname'];?></A><br/>
					<?php }?>
				  </TD>
				</TR>
			<?php }?>
          </TABLE>
      </td>
    </tr>
	

</table>

<?php include("../includes/footer.php");?>